home *** CD-ROM | disk | FTP | other *** search
- Path: rap.SanDiegoCA.ATTGIS.COM!news
- From: borisb@sd.znet.com (Boris Burtin)
- Newsgroups: comp.lang.c++
- Subject: Array of multiple types
- Date: Wed, 28 Feb 1996 22:58:34 GMT
- Organization: Lunapark Studios
- Message-ID: <4h2mm0$50l@rap.SanDiegoCA.ATTGIS.COM>
- NNTP-Posting-Host: borisbpc.sandiegoca.attgis.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi,
-
- I'd like to create a query class, which runs a query via ODBC API
- calls and stores the results in a 2D array. The trouble I'm having is
- with the "storing results" part.
-
- Columns returned from a query can be composed of several types--mainly
- string, integer, float and date. So if the user does
-
- SELECT Name, ID, DateOfHire
- FROM Employees
-
- The results will come back as a [3][n] array with the types of string,
- integer, and date for each respective column. The array must be
- created dynamically, and store each element in its native type.
-
- Does anyone have an idea about how I could do this? The cleanest
- solution I came up with is to derive each data type from a base class:
-
- class Cell
- {
- public:
- virtual int GetInt();
- virtual string GetString();
- // etc.
- }
-
- class IntCell : Cell
- {
- private:
- int data;
- public:
- int GetInt() { return data; }
- }
-
- The query results class would then contain a 2D array of Cells. This
- approach should work, but it doesn't seem very effective to come up
- with a whole new data type that only stores an integer.
-
- Does someone have a better plan? Templates maybe?
-
- Thanks,
-
- Boris
-
-
-